package com.example.clock.planPage;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.clock.R;
import com.example.clock.basicClass.Plan;

import org.w3c.dom.Text;

import java.util.ArrayList;

public class PlanAdapter extends ArrayAdapter<Plan> {
    public PlanAdapter(@NonNull Context context, int resource, @NonNull ArrayList<Plan> objects) {

        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Plan p= getItem(position);//得到当前项的 plan 实例
        //为每一个子项加载设定的布局
        View view= LayoutInflater.from(getContext()).inflate(R.layout.list_item_1,parent,false);
        //分别获取 image view 和 textview 的实例
        TextView textView1 = view.findViewById(R.id.textView21);
        TextView textView2 = view.findViewById(R.id.textView22);
        TextView textView3 = view.findViewById(R.id.textView30);
        TextView textView4 = view.findViewById(R.id.textView31);
        TextView textView5 = view.findViewById(R.id.textView32);

        // 设置要显示的图片和文字
        textView1.setText(p.getPlanName());
        if(p.getPlanName() != "点击新建计划") {
            textView3.setText(p.getLargeTags());
            textView4.setText(p.getSmallTags());
            textView2.setText(p.getStartDate() + "——" + p.getEndDate());
            textView5.setText("累计打卡" + p.getFinishTimes() + "次");
        }
        else {

        }


        return view;
    }
}
